const utils = require('j7/utils');

const tasks = {};

function add(clsNames, modName) {
  const modClass = require('./' + modName);
  clsNames.forEach((clsName) => {
    tasks[clsName] = {
      'clsName': clsName,
      'modName': modName,
      'class': modClass
    };
  });
}

async function init() {
  add(['DbSpider'], 'dbspider');
  const initTasks = [
    'DbSpider'
  ];
  await utils.serial(
    [
      'DbSpider'
    ],
    async (name) =>
      {
        const task = create(name);
        await task.init();
      });
}

function create(name) {
  const module = tasks[name];
  return new module['class']();
}

exports.init = init;
